package com.projet.xh;

import com.core.common.FormatKit;

import java.util.ArrayList;
import java.util.List;

public class TestXH {
    public static void main(String[] args) {
        TqzzBomServer tool = new TqzzBomServer();
        List<PrdBomVO> resList = tool.buildTree(build01(), "root");
        print(resList, "");

    }

    public static void print(List<PrdBomVO> resList, String pre) {
        for (PrdBomVO prdBomVO : resList) {
            System.out.print(FormatKit.format(pre + prdBomVO.getMaterialNo(), 30));
            System.out.print("    ");
            System.out.print(FormatKit.format(prdBomVO.getDirectLeaderNo(), 5));
            System.out.print("    ");
            if (prdBomVO.getProductType().equals("ZP")) {
                System.out.print("装配");
            } else {
                System.out.print("自制");
            }
            System.out.print("    ");
            if (prdBomVO.getSortNo() == null) {
                System.out.print(" ");
            } else {
                System.out.print(prdBomVO.getSortNo());
            }

            System.out.println("    ");

            if (prdBomVO.getChildren() != null) {
                print(prdBomVO.getChildren(), pre + "     ");
            }
        }
    }

    public static List<PrdBomVO> build01() {
        List<PrdBomVO> list = new ArrayList<>();
        list.add(vo("A", "root", "PZ"));
        list.add(vo("A1", "A", "PZ"));
        list.add(vo("A11", "A1", "PZ"));

        list.add(vo("B", "root", "PZ"));
        list.add(vo("B1", "B", "PZ"));
        list.add(vo("B11", "B1", "PZ"));
        list.add(vo("B2", "B", "ZP"));
        list.add(vo("B21", "B2", "ZP"));
        list.add(vo("B211", "B21", "PZ"));
        list.add(vo("B212", "B21", "PZ"));
        list.add(vo("B22", "B2", "PZ"));


        list.add(vo("C", "root", "PZ"));
        list.add(vo("C1", "C", "PZ"));
        list.add(vo("C11", "C1", "PZ"));
        int idx = 0;
        for (PrdBomVO prdBomVO : list) {
            prdBomVO.setSortNum(idx++);
        }
        return list;
    }


    public static List<PrdBomVO> build02() {
        List<PrdBomVO> list = new ArrayList<>();
        list.add(vo("A", "root", "PZ"));
        list.add(vo("A1", "A", "PZ"));
        list.add(vo("A11", "A1", "PZ"));

        list.add(vo("B", "root", "ZP"));
        list.add(vo("B1", "B", "PZ"));
        list.add(vo("B11", "B1", "PZ"));
        list.add(vo("B2", "B", "ZP"));
        list.add(vo("B21", "B2", "ZP"));
        list.add(vo("B211", "B21", "PZ"));
        list.add(vo("B212", "B21", "PZ"));
        list.add(vo("B22", "B2", "PZ"));


        list.add(vo("C", "root", "PZ"));
        list.add(vo("C1", "C", "PZ"));
        list.add(vo("C11", "C1", "PZ"));
        int idx = 0;
        for (PrdBomVO prdBomVO : list) {
            prdBomVO.setSortNum(idx++);
        }
        return list;
    }


    public static List<PrdBomVO> build03() {
        List<PrdBomVO> list = new ArrayList<>();
        list.add(vo("A", "root", "ZP"));
        list.add(vo("A1", "A", "PZ"));
        list.add(vo("A11", "A1", "PZ"));
        list.add(vo("A2", "A", "PZ"));
        list.add(vo("A21", "A2", "PZ"));

        list.add(vo("B", "root", "ZP"));
        list.add(vo("B1", "B", "PZ"));
        list.add(vo("B11", "B1", "PZ"));
        list.add(vo("B12", "B1", "PZ"));
        list.add(vo("B2", "B", "PZ"));
        list.add(vo("B21", "B2", "PZ"));
        list.add(vo("B22", "B2", "PZ"));

        list.add(vo("C", "root", "PZ"));
        list.add(vo("C1", "C", "PZ"));
        list.add(vo("C11", "C1", "PZ"));
        int idx = 0;
        for (PrdBomVO prdBomVO : list) {
            prdBomVO.setSortNum(idx++);
        }
        return list;
    }


    public static PrdBomVO vo(String materialNo, String parentNo, String type) {
        PrdBomVO n = new PrdBomVO();
        n.setMaterialNo(materialNo);
        n.setDirectLeaderNo(parentNo);
        n.setProductType(type);
        n.setMaterialGroupNo(type);
        return n;
    }
}
